package com.taiic.deepseektest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.taiic.deepseek.DsManager;
import com.taiic.deepseek.rkllm.LLMCallState;
import com.taiic.deepseek.rkllm.RKLLMResult;
import com.taiic.deepseek.rkllm.onRkllmResult;

import com.taiic.deepseektest.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, onRkllmResult {

    // Used to load the 'deepseektest' library on application startup.


    private ActivityMainBinding binding;
    private String TAG = "deepseek";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Example of a call to a native method
        TextView tv = binding.sampleText;
        tv.setText("test big model");

        boolean ret = DsManager.GetInstance().initializeModel("/data/demo_Android_arm64-v8a/DeepSeek-R1-Distill-Qwen-1.5B_W8A8_RK3588.rkllm",2048, 4096, this);
        Log.d(TAG, "onCreate: " + ret);
    }

    @Override
    public void onClick(View view) {

    }
    int count= 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        count = count + 1;
        Log.d(TAG, "onKeyDown: "+ count);
        if(count % 2 == 1){

            DsManager.GetInstance().runModel("写一首以梅花为主题的七言绝句，不用分析，不用赏析，直接写诗就行");
//        DsManager.GetInstance().runModel("现有一笼子，里面有鸡和兔子若干只，数一数，共有头14个，腿38条，求鸡和兔子各有多少只？");
//        DsManager.GetInstance().run("有28位小朋友排成一行,从左边开始数第10位是学豆,从右边开始数他是第几位?");
//            DsManager.GetInstance().testJava();
        };

        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DsManager.GetInstance().destoryModel();
    }

    @Override
    public void rkllmResult(RKLLMResult result, Object userdata, LLMCallState state) {
        Log.d(TAG, "rkllmResult: " + result.getText());
    }

    @Override
    public void rkllmResultSimple(String result, int state) {
        Log.d(TAG, "rkllmResult: " + result + ", state: " + state);
    }

    @Override
    public void rkllmFinish() {
        Log.d(TAG, "rkllmFinish: ");
    }
}